/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package analyzer;

import java.util.ArrayList;
import java.util.List;
import human.Parameter;

/**
 *
 * @author Admin
 */
class KnowledgeBase {

    private List<Knowledge> knowledges;

    public KnowledgeBase() {
        knowledges = new ArrayList<Knowledge>(3);
    }

    String getRecipe(Parameter parametr) {
        int search = parametr.getValue();

        for (Knowledge know : knowledges) {
            if (know.isIn(search)) {
                return parametr.getName() + ": " + know;
            }
        }
        return parametr.getName() + ": " + "Data is not found";
    }

    void addKnowledge(int lowValue, int hightValue, String string) {
        Knowledge knowledge = new Knowledge(lowValue, hightValue, string);

        if (!isPresent(knowledge)) {
            knowledges.add(knowledge);
        }
    }

    private boolean isPresent(Knowledge knowledge) {
        for (Knowledge know : knowledges) {
            if (know.isIntersection(knowledge)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder(13);
        for (Knowledge know : knowledges) {
            result.append(know);
            result.append("\n");
        }
        return result.toString();
    }
}
